package demo.web.controller;

import demo.model.Account;
import demo.service.AccountService;
import demo.utils.JdbcPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by IntelliJ IDEA.
 * User: zigang.wang
 * Date: 12-3-19
 * Time: 上午10:48
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("/account/*")
public class AccountCtrl {
    @Autowired
    AccountService accountService;
    @RequestMapping(value = "list")
    public String list(HttpServletRequest request, HttpServletResponse response){
        int curPage = ServletRequestUtils.getIntParameter(request, "curPage", 1);
        int pageSize = ServletRequestUtils.getIntParameter(request, "pageSize", 2);
        int status = ServletRequestUtils.getIntParameter(request, "status", 0);
        JdbcPage<Account> accountPage = accountService.listAccount(curPage, pageSize, status);
        request.setAttribute("accountPage", accountPage);

        return "list";
    }

    @RequestMapping(value = "/view/{id}")
    public String view(@PathVariable long id){
        Account account = accountService.getById(id);
        return "list";
    }
}
